<template>
    <div class="header">
        <div class="header-left">
            中部地区
            <van-icon name="arrow" />
        </div>
        <van-search
                v-model="searchValue"
                shape="round"
                placeholder="请输入搜索关键词"
                />
    </div>
    <van-swipe height="170px" class="my-swipe" :autoplay="3000" indicator-color="white">
  <van-swipe-item v-for="item in homeData.slides" :key="item.id">
    <van-image radius="5" :src="item.pic_image_url" fit="cover" />
  </van-swipe-item>
    </van-swipe>
    <van-row justify="space-around">
        <van-col 
        v-for="(item,index) in homeData.nav2s"
        :key="item.id"
        span="11"
        class="center-img"
        @click="fastgoOrder(index)">
            <van-image :src="item.pic_image_url"/>
        </van-col>
    </van-row>
    <van-row @click="goOrder(item)" class="hospital-list" v-for="item in homeData.hospitals" justify="space-around">
        <van-col span="6">
            <van-image width="100px"
            radius="5px"
            height="90px"
            :src="item.avatar_url"/>
        </van-col>
        <van-col span="16" class="hospital">
            <div class="hospital-name">{{ item.name }}</div>
            <div class="hospital-type">
                <span>{{ item.rank }} </span>
                &nbsp
                <span>{{ item.label }} </span>
            </div>
            <div class="hospital-text">{{ item.intro }}</div>
        </van-col>
    </van-row>
</template>
<script setup>
import { ref ,onMounted} from 'vue'
import { getCurrentInstance, reactive } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 获取当前vue实例
const { proxy } = getCurrentInstance()

const searchValue = ref('')

const goOrder = (item) => {
    router.push(`/createOrder?id=${item.id}`)
}


onMounted(async() => {
    const res = await proxy.$api.homeIndex()
    console.log(res,'res')
    console.log(res.data,'res.data')
    Object.assign(homeData,res.data.data)
    console.log(homeData,'homeData')
})

const homeData = reactive({
    hospitals:[],
    nav2s:[],
    navs:[],
    now:'',
    slides:[]
})

const fastgoOrder = (index) => {
    router.push(`/createOrder?id=${homeData.hospitals[index].id}`)
}



</script>
<style lang="less" scoped>
.header {
    display: flex;
    justify-content: space-between;
    margin: 5px;
    line-height: 54px;
    .header-left {
      padding-left: 22px;
      background: url()
        no-repeat left center;
      background-size: 20px;
      font-size: 20px;
      font-weight: bold;
      color: #666666;
    }
  }
  .my-swiper {
    margin: 5px;
  }
  .hospital-list {
    padding-bottom: 10px;
    margin: 20px 0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.04), 0 1px 6px 0 rgba(0, 0, 0, 0.04);
    .hospital {
      .hospital-name {
        font-size: 20px;
        line-height: 30px;
        font-weight: bold;
      }
      .hospital-type {
        font-weight: bold;
        line-height: 25px;
        font-size: 15px;
        color: #0ca7ae;
      }
      .hospital-text {
        font-size: 14px;
        color: #999999;
      }
    }
  }
  .bottom-text {
    line-height: 50px;
    text-align: center;
    color: #999999;
  }
</style>